import time

from modelscope.utils.constant import Tasks
from modelscope.pipelines import pipeline
import cv2
from modelscope import snapshot_download
# https://www.modelscope.cn/models/AI-ModelScope/stable-diffusion-v1-5
#pip install accelerate\
# 还能使用,但是需要使用英文prompt
model_base_path = 'E:/workspace/llm/text2image/models'
current_milliseconds = time.time()
download = snapshot_download('AI-ModelScope/stable-diffusion-v1-5', cache_dir=model_base_path)
pipe = pipeline(task=Tasks.text_to_image_synthesis,
                model='AI-ModelScope/stable-diffusion-v1-5',
                model_revision='v1.0.0')

prompt = 'A beautiful girl in the sunshine'
output = pipe({'text': prompt})
cv2.imwrite('result11.png', output['output_imgs'][0])
print(time.time()-current_milliseconds)